//
//  InpOperationVC.m
//  掌上宏力
//
//  Created by admin on 2017/5/16.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "InpOperationVC.h"
#import "InpOperationModel.h"
#import "InpOperatorCell.h"
#import "InOperatorViewModel.h"

@interface InpOperationVC ()

@property (nonatomic,strong) InOperatorViewModel *viewModel;
@property (nonatomic,strong) NSMutableArray *datasArray;

@end

@implementation InpOperationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"手术信息";
}

-(void)getDatasArray{
    [self getDatasArray:^(NSString *page, GetDatas handler) {
        _viewModel = [[InOperatorViewModel alloc] init];
        NSString *p = [NSString stringWithFormat:@"%ld",self.currentPage];
        [_viewModel getInOperatorInfoWithPage:p success:^{
            if (self.currentPage == 1) {
                _datasArray = [NSMutableArray arrayWithArray:_viewModel.datasArray];
            }else{
                [_datasArray addObjectsFromArray:_viewModel.datasArray];
            }
            handler(_viewModel.datasArray);
        }];
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _datasArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    InpOperationModel *model = _datasArray[section];
    NSString *dateStr = model.opDate;
    return [dateStr substringToIndex:dateStr.length-8];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InpOperatorCell *cell = [InpOperatorCell cellWithTableView:tableView];
    cell.opModel = _datasArray[indexPath.section];
    return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == _datasArray.count - 1) {
        self.currentPage ++;
        [self getDatasArray];
    }
}

@end
